<template>
	<view class="goods-info-view">
		<!-- 轮播图 -->
		<u-swiper :list="list1" height="260" radius="0"></u-swiper>
		<!-- 内容 -->
		<view class="padding-30">
			<view class="bg-fff border-radius20 padding-30 margin-bottom30">
				<view style="color: #C90F0F;" class="margin-bottom20">
					<text class="fontSize-15">￥</text>
					<text class="fontSize-30 fontWeight-bold">{{goodsDetail.price}}</text>
				</view>
				<view class="fontSize-15 color-704234 margin-bottom20">{{goodsDetail.title}}</view>

				<view class="flex-flex-warp">
					<block  v-for="(item,index) in tagList" :key="index">
						<view class="goods-info-tag flex-center" v-if="item">{{item}}</view>
					</block>
				</view>
			</view>
			<view class="bg-fff border-radius20 padding-30 margin-bottom30">
				<view class="fontSize-15 color-704234 margin-bottom30">课程简介</view>
				<view class="fontSize-15 color-704234">
					{{goodsDetail.describes}}
				</view>
			</view>
			<view class="bg-fff border-radius20 padding-30 margin-bottom30">
				<view class="fontSize-15 color-704234 margin-bottom30">课程介绍</view>
				<view class="fontSize-15 color-704234">
					<u-parse  :content="goodsDetail.content"></u-parse>
				</view>
			</view>
			<!-- 底部操作栏 -->
			<view style="height: 200rpx;"></view>
			<view class="position-fixed-94bottom padding-20" style="background-color: #ffffff;" @click="buyShow = true">
				<view class="btn-C1A17C-D6B792 flex-center flex1">
					立即购买
				</view>
			</view>
		</view>

		<!-- 购买弹窗 -->
		<u-popup :show="buyShow" mode="center" bgColor="#F6F3E8" round="20">
			<view class="flex-justAliCenter-column popup-view">
				<view class="fontSize-18 fontWeight-bold color-704234">课程详情</view>
				<view class="buy-center" style="background: url('../../../static/image/11.png') no-repeat; background-size: 100% 100%;">
					<!-- <image class="buy-center-image" src="" mode=""></image> -->
					<view class="buy-center-view1">
						<view class="fontSize-15 color-704234 margin-bottom30">
							<!-- <text class="margin-right20">购买课程</text> -->
							<text style="word-wrap: break-word;">{{goodsDetail.title}}</text>
							<!-- <text style="word-wrap: break-word;">12312321321sxczxczxcZczxczczxcasdsadsadsadsadsadsadsada</text> -->
						</view>
						<view class="fontSize-15 color-704234">
							<text class="margin-right20">学习次数</text>
							<text>共{{goodsDetail.course_count}}节</text>
						</view>
					</view>
				</view>
				<view class="buy-btn flex-center fontSize-15 color-704234" @click="confirmBuy">确认购买</view>
				<view class="fontSize-15 color-704234 margin-top30 text-center" @click="buyShow = false">暂不购买</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list1: [],
				buyShow: false,
				goodsDetail:{},
				goods_id:'',
				tagList:[],
			}
		},
		onLoad(e) {
			console.log(e)
			this.goods_id = e.goods_id
			this.getGoodsDetail()
		},
		methods:{
			async getGoodsDetail(){
				let res = await this.$http.post(this.$api.goods_detail,{goods_id:this.goods_id},{token:true})
				this.goodsDetail = res.data.goods
				this.list1 = res.data.goods.images
				this.tagList = res.data.goods.tag.split(',')
				console.log(this.tagList)
			},
			// 创建订单
			 async confirmBuy(){
			     let res = await this.$http.post(this.$api.order_create,{
					 goods_id:this.goodsDetail.id
				 },{token:true})
				 console.log(res)
				 if(res.code ==1){
					 this.payOrder(res.data.order_no)
				 }
			},
			// 支付
			async payOrder(order_no){
				let res = await this.$http.post(this.$api.order_test,{order_no:order_no},{token:true})
				// let res = await this.$http.post(this.$api.pay,{order_no:order_no,pay_type:1},{token:true})
				console.log(res)
				this.buyShow = false
				this.$tools.toast('支付成功')
			}
		}
	}
</script>

<style lang="scss" scoped>
	.buy-btn{
		width: 100%;
		height: 90rpx;
		background: linear-gradient( 130deg, #E2BF94 0%, #E5C6A0 28%, #E6CDB1 56%, #D1AA79 100%);
	}
	.buy-center-view1{
		width: 380rpx;
		// height: 220rpx;
		background-color: #EFDFCD;
		padding: 30rpx;
	}
	.buy-center{
		// position: relative;
		margin: 30rpx 0;
		width:500rpx;
		height: 360rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	// .buy-center-image{
	// 	width: 100%;
	// 	height: 100%;
	// 	flex-shrink: 0;
	// }
	.popup-view {
		padding: 30rpx;
		width: 500rpx;
		background-color: #F6F3E8;
	}

	.goods-info-tag {
		padding: 5rpx 10rpx;
		font-weight: 400;
		font-size: 24rpx;
		color: #947065;
		background: rgba(148, 112, 101, 0.14);
		border-radius: 20rpx;
		border: 1rpx solid #967C5E;
		margin: 0 20rpx 20rpx 0;
	}

	.goods-info-view {
		background-color: #F5F1E8;
		min-height: 100vh;
	}
</style>